package com.erdos.message.channel;

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

import com.erdos.message.entity.MessageChannel;


public class ChannelChain {

	private MessageChannel currentChannel=NullMessageChannel.getInstance();
	
	private MessageChannel prevChannel=NullMessageChannel.getInstance();
	
	private Set <MessageChannel> nextChannels=new TreeSet<MessageChannel>();
	
	/** a <code>RouteSelector</code> class name, 
	 * with package as the prefix, like, com.hp.message.DefaultRouteSelector 
	 **/
	private String routeSelector;
	
	public ChannelChain() {
		
	}
	
	public MessageChannel getCurrentChannel() {
		return currentChannel;
	}

	public void setCurrentChannel(MessageChannel currentChannel) {
		this.currentChannel = currentChannel;
	}

	public MessageChannel getPrevChannel() {
		return prevChannel;
	}

	public void setPrevChannel(MessageChannel prevChannel) {
		this.prevChannel = prevChannel;
	}

	public void addNextChannel(MessageChannel channel) {
		this.nextChannels.add(channel);
	}
	
	public boolean removeNextChannel(MessageChannel channel) {
		return this.nextChannels.remove(channel);
	}
	
	public void clearNextChannel() {
		this.nextChannels.clear();
	}
	/**
	 * returns an Iterator of the next MessageChannel.
	 * @return an Iterator of the next MessageChannel
	 */
	public Iterator<MessageChannel> iterate() {
		return this.nextChannels.iterator();
	}
	
	public boolean isEmpty() {
		return this.currentChannel.equals(NullMessageChannel.getInstance());
	}	

	public String getRouteSelector() {
		return routeSelector;
	}

	public void setRouteSelector(String routeSelector) {
		this.routeSelector = routeSelector;
	}	
}
